package org.jfk.tbox.net.app;

import org.jfk.core.utils.ByteUtils;
import org.jfk.tbox.net.TboxMsg;
import org.jfk.tbox.net.app.TBOX_DeviceStatus.TBOX_DeviceStatusResp;

public class TBOX_Activate {
	static final String appId = "0202";

	public class TBOX_ActivateReq extends TboxMsg{
		String sim = null;
		public TBOX_ActivateReq(){
			super.appId = TBOX_Activate.appId;
			super.msgId = 1;
		}
		
		public void loadData(byte[] data){
			super.loadData(data);
			sim = ByteUtils.bytesToASCII(super.appData);
		}
		
		
		public byte[] getAppData(){
			return null;
		}
		
		public byte[] getResp(){
			TBOX_ActivateResp resp = new TBOX_ActivateResp();
			resp = (TBOX_ActivateResp) super.initResp(this);
			resp.seed = "04030201";
			resp.tBoxStatus = 1;
			resp.securityCtx = ByteUtils.hexStringToBytes("0000");
			resp.scCtxVer = 0;
			return resp.toBytes();
		}
	}
	
	
	public class TBOX_ActivateResp extends TboxMsg{
		
		//0:NoActive;1:Active;2:Stop Business
		public byte tBoxStatus = 1;
		
		//数据加密密钥
		public byte[] securityCtx = {0x00,0x00};
		
		//密钥版本号 0..255
		public byte scCtxVer = 0;
		

		public TBOX_ActivateResp(){
			super.appId = TBOX_Activate.appId;
			super.msgId = 2;
		}
		
		
		public byte[] getAppData(){
			byte[] _tBoxStatus = {tBoxStatus};
			byte[] _seed = ByteUtils.hexStringToBytes(super.seed);
			byte[] _securityCtx = securityCtx;
			byte[] _scCtxVer = {scCtxVer};
			byte[] b = new byte[_tBoxStatus.length + _seed.length + _securityCtx.length + _scCtxVer.length];
			
			int idx = 0;
			System.arraycopy(_tBoxStatus, 0, b, idx, _tBoxStatus.length);
			idx = idx + _tBoxStatus.length;
			
			System.arraycopy(_seed, 0, b, idx, _seed.length);
			idx = idx + _seed.length;
			
			System.arraycopy(_securityCtx, 0, b, idx, _securityCtx.length);
			idx = idx + _securityCtx.length;

			System.arraycopy(_scCtxVer, 0, b, idx, _scCtxVer.length);
			idx = idx + _scCtxVer.length;
		
			return b;
		}
		
		public byte[] getResp(){
			return null;
		}
		
	}
	public class TBOX_ActivateAck extends TboxMsg{
		public TBOX_ActivateAck(){
			super.appId = TBOX_Activate.appId;
			super.msgId = 3;
		}		
		//0:失败;1:成功
		public byte activeAck;
		
		public byte[] getAppData(){
			return null;
		}
		
		public byte[] getResp(){
			return null;
		}
		
	}
}

